<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
    window.onload = function () {
        // 键盘事件
        document.onkeydown = function (event) {
            event = event || window.event;
            // 判断是否y被按下
            if (event.keyCode === 89 && event.keyCode) {
                console.log("y被按下了");
            }
            document.onkeyup = function () {
                console.log("按键松开了");
            };
        }
    }
</script>

<body>

</body>

</html>